﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestLink2Net.Bal.Interfaces;
using TestLink2Net.Entities;
using TestLink2Net.Dal;

namespace TestLink2Net.Bal
{
    public class SecurityManager : ISecurityManager
    {
        private SecurityManager()
        {
        }

        public static ISecurityManager Instance
        {
            get
            {
                return new SecurityManager();
            }
        }



        #region ISecurityManager Members

        public bool ValidateUser(string userName, string password)
        {
            try
            {
                if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
                {
                    User user = SecurityDB.Instance.GetUser(userName);
                    if (user != null)
                    {
                        if (user.Password == Util.GetHash(password))
                        {
                            return true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return false;
        }

        #endregion

    }
        
}
